package cn.xo68.ide.plugin.action;

import cn.xo68.ide.plugin.common.component.StarupApplicationComponent;
import cn.xo68.ide.plugin.ui.form.CreateProjectDialog;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;

public class CreateProjectAction extends AnAction {

    @Override
    public void actionPerformed(AnActionEvent e) {
        StarupApplicationComponent starupApplicationComponent = StarupApplicationComponent.getInstance();
        if(!starupApplicationComponent.templateConfigExists()){
            ApplicationManager.getApplication().invokeLater(()-> {
                Messages.showMessageDialog(
                        "请先配置插件设置，更新数据！"
                        , "操作提示"
                        , Messages.getInformationIcon());
            });
        }

        starupApplicationComponent.setLastOperateProject(e.getProject());
        Project selectedProject = e.getProject();
        // 当前选中的目录
        VirtualFile selectedFile = e.getData(LangDataKeys.VIRTUAL_FILE);
        CreateProjectDialog.open(selectedProject,selectedFile);
    }
}
